﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;
using ww.lis.lisbll.sam;
using System.Collections;
using System.IO;

namespace ww.form.lis.sam.jy
{
    public partial class QC_DataSet : ww.form.wwf.SysBaseForm
    {
        string finstr_id = "";
        string fjy_id = "";
        DataTable dtZKP = new DataTable();//当前项目表
        ItemBLL bllItem = new ItemBLL();//项目逻辑        
        jybll blljy = new jybll();

        public QC_DataSet(string finstrid, string fjyid)
        {
            InitializeComponent();
            finstr_id = finstrid;
            fjy_id = fjyid;
        }

        private void GetZK_ZKP()
        {
            try
            {
                if (dtZKP != null)
                    dtZKP.Clear();
                dtZKP = this.bllItem.BllZKP(1, finstr_id);
                this.comboBox质控品.DataSource = dtZKP;
            }
            catch (Exception ex)
            {
                WWMessage.MessageShowError(ex.ToString());
            }
        }

        private void QC_DataAutoForm_Load(object sender, EventArgs e)
        {
            GetZK_ZKP();
            fjy_dateDateTimePicker1.Value = Convert.ToDateTime(WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "select fjy_date from SAM_JY where fjy_id='" + fjy_id + "'"));
            fjy_dateDateTimePicker2.Value = fjy_dateDateTimePicker1.Value;
            lbl_finstr.Text = lbl_finstr.Text + WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "select fname from SAM_INSTR where finstr_id='" + finstr_id + "'");
            //lbl_zkp.Text = lbl_zkp.Text + WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "SELECT 中文名称+'|'+批号+'|'+生产厂家+'|'+convert(varchar(10),使用日期,121) 质控品 FROM SAM_ZK_ZKP  where 编号='" + fzkp_id + "'");
        }

        private void buttonTC_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button保存_Click(object sender, EventArgs e)
        {
            if (fjy_dateDateTimePicker2.Value < fjy_dateDateTimePicker1.Value)
            {
                WWMessage.MessageShowError("日期范围有误，请检查！");
                this.ActiveControl = fjy_dateDateTimePicker1;
                return;
            }

            if (object.Equals(null, comboBox质控品.SelectedValue))
            {
                WWMessage.MessageShowError("质控品未选择，请检查！");
                this.ActiveControl = comboBox质控品;
                return;
            }

            //if (WWMessage.MessageDialogResult("该操作会自动覆盖以前的质控数据，你确认码？"))
            //{
            //    int intRRR = this.blljy.UpdateZK(fjy_id, comboBox质控品.SelectedValue.ToString());
            //    WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "exec Lis_Ins_Result_QCDataAuto '" + finstr_id + "','" + comboBox质控品.SelectedValue.ToString() + "','" + fjy_dateDateTimePicker1.Value.ToString("yyyy-MM-dd") + "','" + fjy_dateDateTimePicker2.Value.ToString("yyyy-MM-dd") + "'");
            //    this.DialogResult = DialogResult.OK;
            //}

            int intRRR = this.blljy.UpdateZK(fjy_id, comboBox质控品.SelectedValue.ToString());
            WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "exec Lis_Ins_Result_QCDataAuto '" + finstr_id + "','" + comboBox质控品.SelectedValue.ToString() + "','" + fjy_dateDateTimePicker1.Value.ToString("yyyy-MM-dd") + "','" + fjy_dateDateTimePicker2.Value.ToString("yyyy-MM-dd") + "'");
            this.DialogResult = DialogResult.OK;
        }


    }
}